package demo1;


import java.util.Objects;

class Son {
    public String name;
    public int age;

    public Son(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Son son = (Son) o;
        return age == son.age && Objects.equals(name, son.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
public class Test2 {
    public static void main(String[] args) {
        Son son1 = new Son("张三",12);
        Son son2 = new Son("张三",12);
        Son son3 = new Son("李四",122);
        System.out.println(son1.hashCode());
        System.out.println(son2.hashCode());
    }
    public static void main2(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("abc");
        System.out.println(s1.equals(s2));
    }
    public static void main1(String[] args) {
        String s1 = "abc";
        String s2 = "abc";
        String s3 = "abcd";
        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
    }
}
